﻿using CuaHangLego.Bussiness.Parser;
using CuaHangLego.Model;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CuaHangLego.DataAccess
{
    public class NhaCungCapDA : DABase, IDA<NhaCungCap>
    {
        public static NhaCungCapDA Instance = new NhaCungCapDA();

        public int Insert(NhaCungCap item)
        {
            throw new NotImplementedException();
        }

        public bool Update(NhaCungCap item)
        {
            throw new NotImplementedException();
        }

        public bool Delete(NhaCungCap item)
        {
            throw new NotImplementedException();
        }

        public IList<NhaCungCap> GetAll()
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = string.Format("SELECT * FROM NHACUNGCAP");
            cmd.CommandType = System.Data.CommandType.Text;
            OpenDB();
            SqlDataReader reader = ExecuteQueryReader(cmd);
            IList<NhaCungCap> list = new List<NhaCungCap>();
            while (reader.Read())
            {
                list.Add(NhaCungCapParser.Parse(reader));
            }
            CloseDB();
            return list;
        }

        public NhaCungCap GetByID(int ID)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = string.Format("SELECT * FROM NHACUNGCAP WHERE {0}={1}", "ID", ID);
            cmd.CommandType = System.Data.CommandType.Text;
            OpenDB();
            SqlDataReader reader = ExecuteQueryReader(cmd);
            NhaCungCap sp = new NhaCungCap();
            while (reader.Read())
            {
                sp = NhaCungCapParser.Parse(reader);
                break;
            }
            CloseDB();
            return sp;
        }
    }
}
